package chapter4.No4_1_使用reentrantLock类.demo12;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by Administrator on 2016/11/21.
 */
public class ServiceClass3 {
    ReentrantLock lock = new ReentrantLock();
    Condition condition = lock.newCondition();

    public void methodA() {
        lock.lock();
        try {
            System.out.println("线程" + Thread.currentThread().getName() + "进入waiting状态");
            condition.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        lock.unlock();
    }

    public int getWaitSize() {
        int waitCount = 0;
        lock.lock();
        waitCount = lock.getWaitQueueLength(condition);
        lock.unlock();
        return waitCount;
    }
}
